from sqlalchemy import Column, Integer, String, Text, DateTime, ForeignKey, BigInteger, Boolean
from sqlalchemy.orm import relationship
from datetime import datetime
from ..database import Base

class Document(Base):
    __tablename__ = "documents"
    
    id = Column(Integer, primary_key=True, index=True)
    filename = Column(String(255), nullable=False)
    original_filename = Column(String(255), nullable=False)
    file_path = Column(String(500), nullable=False)
    file_size = Column(BigInteger)  # 文件大小（字节）
    file_type = Column(String(50))  # 文件类型：pdf, docx, txt等
    content = Column(Text)  # 提取的文本内容
    
    # 处理状态
    loader_type = Column(String(50))  # 加载器类型
    splitter_type = Column(String(50))  # 分词器类型
    chunk_count = Column(Integer, default=0)  # 分块数量
    is_processed = Column(Boolean, default=False)  # 是否已处理
    is_vectorized = Column(Boolean, default=False)  # 是否已向量化
    
    created_at = Column(DateTime, default=datetime.utcnow)
    updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
    
    # 外键
    knowledge_base_id = Column(Integer, ForeignKey("knowledge_bases.id"))
    
    # 关系
    knowledge_base = relationship("KnowledgeBase", back_populates="documents") 